﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Obra.Sync;

namespace Obra.CommandLineInterface
{
    internal class DryRunSyncServiceProvider :
        ISyncService
    {
        private readonly ISyncService syncService;

        private void Log(string message, MediaItemMetadata mediaItemMetadata)
        {
            string logMessage = String.Format("{0} {1}/{2}",
                message,
                mediaItemMetadata.AlbumName,
                mediaItemMetadata.MediaName);

            this.Log(logMessage);
        }

        private void Log(string message)
        {
            Console.WriteLine(String.Format("[{0}] {1}",
                DateTime.Now.ToString(),
                message));
        }

        /// <summary>
        /// c-tor
        /// </summary>
        public DryRunSyncServiceProvider(
            ISyncService syncService)
        {
            this.syncService = syncService;
        }

        #region ISyncService Members

        public string Name
        {
            get { return this.syncService.Name; }
        }

        public string Description
        {
            get { return this.syncService.Description; }
        }

        public void Connect()
        {
            this.Log("Connect()");
            this.syncService.Connect();
        }

        public void Disconnect()
        {
            this.Log("Disconnect()");
            this.syncService.Disconnect();
        }

        public SyncOptions SyncOptions
        {
            get { return this.syncService.SyncOptions; }
        }

        public string ComputeChecksum(MediaItemMetadata mediaItemMetadata)
        {
            this.Log("ComputeChecksum()", mediaItemMetadata);
            return this.syncService.ComputeChecksum(mediaItemMetadata);
        }

        public void DeleteMediaFile(MediaItemMetadata mediaItemMetadata)
        {
            this.Log("DeleteMediaFile()", mediaItemMetadata);
        }

        public List<MediaItemMetadata> EnumerateMediaFiles()
        {
            this.Log("EnumerateMediaFile()");
            return this.syncService.EnumerateMediaFiles();
        }

        public void SaveChange(ISyncItemTransfer syncItemTransfer)
        {
            this.Log("SaveChange()", syncItemTransfer.MediaItemMetadata);
        }

        public ISyncItemTransfer LoadChange(string mediaFileName)
        {
            this.Log(String.Format("LoadChange(): {0}", mediaFileName));
            return this.syncService.LoadChange(mediaFileName);
        }

        #endregion
    }
}
